import config from './common/config.js';
Vue.prototype.$config = config;
import App from './App'
import {
	router,
	RouterMount
} from './router.js'
Vue.use(router);

import ElementUI from 'element-ui';
import './element-ui.scss';
Vue.use(ElementUI);

import core_enums from './common/core_enums.js';
Vue.use({
	install(Vue) {
		Vue.prototype.$core_enums = function(name) {
			if (typeof(core_enums[name]) == 'undefined') {
				return [];
			}
			var d = [];
			for (var i in core_enums[name]) {
				d.push({
					key: String(i),
					value: core_enums[name][i]
				});
			}
			return d;
		};
	}
});


import Cookies from 'js-cookie';
import axios from 'axios';

import encryption from './common/encryption.js';
Vue.prototype.$encryption = encryption;

axios.defaults.baseURL = config.axios_baseURL;
axios.interceptors.request.use(function(config) {
	// 在发送请求之前做些什么
	config.headers['Authorization'] = JSON.stringify({
		auth: Cookies.get('auth'),
		userid: Cookies.get('userid'),
		username: Cookies.get('username'),
		groupid: Cookies.get('groupid'),
		rsa_token: encryption(),
	});
	return config;
}, function(error) {
	// 对请求错误做些什么
	return Promise.reject(error);
});
axios.interceptors.response.use(function(response) {
	// 对响应数据做点什么
	return response.data;
}, function(error) {
	// 对响应错误做点什么
	if (error.response.status == 401) {
		uni.reLaunch({
			url: '/pages/msg?code=401',
		});
		return error.response;
	}
	if (error.response.status == 403) {
		uni.reLaunch({
			url: '/pages/msg?code=403',
		});
		return error.response;
	}
	return error;
});

Vue.prototype.$axios = axios;


import Aside from './components/Aside.vue';
import Header from './components/Header.vue';
import Footer from './components/Footer.vue';
import CategoryAdd from './components/Category-add.vue';
import CategoryMod from './components/Category-mod.vue';
import CategoryLst from './components/Category-lst.vue';

Vue.component('Aside', Aside);
Vue.component('Header', Header);
Vue.component('Footer', Footer);
Vue.component('CategoryAdd', CategoryAdd);
Vue.component('CategoryMod', CategoryMod);
Vue.component('CategoryLst', CategoryLst);

import tinymce from './common/tinymce.js';
Vue.prototype.$tinymce = tinymce;

import Editor from "@tinymce/tinymce-vue";
Vue.component('TinymceEditor', Editor);

Vue.config.productionTip = false;
// #ifndef VUE3
import Vue from 'vue'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
	...App
})
app.$mount()
// #endif

// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
export function createApp() {
	const app = createSSRApp(App)
	return {
		app
	}
}
// #endif
